//
// Created by ashCheng on 2022/12/20.
//
#include "iostream"
#include "math.h"

int main() {
  // 注意32位对应的是2^31，即第一位对应的是2^0
  std::cout << "int bytes: " << sizeof(int)
            << " unsigned int bytes: " << sizeof(unsigned) << std::endl;  // 4 4
  std::cout << "signed int range: " << long(-pow(2, sizeof(int) * 8 - 1))
            << " ~ " << long(pow(2, sizeof(int) * 8 - 1) - 1)
            << std::endl;  // -2147483648 ~ 2147483647
  std::cout << "unsigned int range: 0 ~ " << long(pow(2, sizeof(int) * 8) - 1)
            << std::endl;  // 0 ~ 4294967295
  unsigned u = 10, u2 = 42;
  std::cout << u2 - u << std::endl;  // 32
  std::cout << u - u2 << std::endl;  // 4294967264   即: -32%(4294967295 - 0 + 1) 最终即为 4294967264，此处注意是用区间长度来取模，而不是最大值.也可以简单计算为区间长度加上负值
  int i = 10, i2 = 42;
  std::cout << i2 - i << std::endl;  // 32
  std::cout << i - i2 << std::endl;  // -32
  std::cout << i - u << std::endl;   // 0
  std::cout << u - i << std::endl;   // 0
  return 0;
}